<template>
  <div class="vuel18n">
    <el-table
      :data="tableData"
      style="width: 65%"
      :row-class-name="tableRowClassName"
    >
      <el-table-column prop="date" :label="$t('date')" width="180">
      </el-table-column>
      <el-table-column prop="name" :label="$t('name')" width="180">
      </el-table-column>
      <el-table-column prop="address" :label="$t('address')"> </el-table-column>
    </el-table>
    <div class="btn">
      <el-button type="primary" @click="change_en">点击切换英文</el-button>
      <el-button type="warning" @click="change_zh">点击切换中文</el-button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
      ],
    };
  },
  methods: {
    tableRowClassName({  rowIndex }) {
      if (rowIndex === 1) {
        return "warning-row";
      } else if (rowIndex === 3) {
        return "success-row";
      }
      return "";
    },
    change_en() {
      //全局属性
      // console.log(this.$i18n)
      this.$i18n.locale = "en";
    },
    change_zh() {
      this.$i18n.locale = "zh";
    },
  },
};
</script>

<style>
.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}

.vuel18n {
  margin-top: 100px;
  width: 97%;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  align-items: center;
  flex-direction: column;
}

.btn {
  margin: 30px auto;
}
</style>